home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-01-31 | 6.0 KB | 139 lines | [TEXT/MPS ] |
- unit UGlobals;
- {$S Main}
-
- (* Global constants, types, typos, and variables for the HeapDemo application *)
- (* Written by Richard Clark (AppleLink, Delphi, GEnie, MCI, MouseHole: RDCLARK *)
- (* Internet: rdclark@apple.com or rdclark@applelink.apple.com) *)
- (* Copyright (c) 1989 by Apple Computer, Inc. All Rights Reserved *)
-
- (* The program works by allocating a 16K block (Well, 16K + something) in the Application *)
- (* Heap, then initializing this block as another Heap Zone. The user is allowed to allocate *)
- (* relocatable and non-relocatable blocks (Handles and Pointers) in this mini-heap, in 1K *)
- (* increments. The handles and pointers which refer to these blocks are stored in an array, *)
- (* and this information is used to draw a diagram of the heap on the screen. The heap is *)
- (* shown in both its "before" and "after" states. *)
-
- (* This program should work on _any_ Macintosh, from the Lisa running MacWorks, to the *)
- (* Macintosh N, where n >= 2 (I hope!). *)
-
- interface
-
- USES
- Types, Memory, Menus, Dialogs;
-
- const
- (* Menu definitions: mXXX are MENU IDs, ixYYYY are items within a given menu *)
- mApple = 1000;
- iaAbout = 1;
-
- mFile = 1001;
- ifOpen = 1;
- ifClose = 2;
- ifQuit = 4;
-
- mEdit = 1002;
- ieUndo = 1;
- ieCut = 3;
- ieCopy = 4;
- iePaste = 5;
- ieClear = 6;
-
- mWindow = 1003;
- imSimpleDialog = 1;
- imComplexDialog = 2;
- imShowLegend = 4;
-
- mSpecial = 1004;
- isEraseHeap = 1;
-
- (* Dialog Resource IDs *)
- dAbout = 1000;
- dShortMemory = 1001;
- dExtendedMemory = 1002;
-
- (* Window resourse IDs *)
- wLegend = 1000;
-
- (* Alert resource IDs *)
- aNoOldHeap = 1000; (* The "look but don't touch" dialog *)
- aBadNumber = 1001; (* The user entered an incorrect memory value *)
- aNoDemoMemory = 1002; (* We couldn't allocate memory in the demo heap *)
- aNoMoreBlocks = 1003; (* We're at our block limit *)
- aConfirmErase = 1004; (* Really erase the heap? *)
-
- (* Window reference constants *)
- MemDialogRefCon = 1;
- LegendRefCon = 2;
-
- (* Other program-specific constants *)
- MyHeapSize = 16; (* Display a 16K Heap *)
- MyArraySize = 17; (* The number of cells alotted to each "Heap" array. This includes 1 *)
- (* "extra" cell so that you can fill up the heap and still be able to try and *)
- (* get another block. (Think of the situation where the heap is full, and you *)
- (* have one or more of the blocks marked as purgeable. In that case, you *)
- (* _could_ allocate another block, so you'll need an array element to hold *)
- (* it. The array element of the purged block will be reclaimed automatically leter *)
- HeapBias = 316; (* 52 bytes for the header, plus 264 bytes for a Master Pointer Block *)
- HeapTrailer = 12; (* The heap is followed by a 12-byte trailer *)
- Slop = 0; (* Allocate an extra 0 bytes of "slop" on our heap *)
- BlockHeaderSize = 8; (* This much is removed from each block allocation so that the physical size matches *)
- (* the requested size *)
-
- (* Block type constants for our "blocks" array *)
- blkFree = 0; (* available for use *)
- blkPointer = 1; (* this is a pointer *)
- blkHandle = 2; (* This is a Handle *)
- blkMaster = 3; (* This is a Master Pointer Block (this constant not used in this release) *)
-
- type
- BlockInfo = record
- blkType: integer; (* free, pointer, or handle *)
- blkSource: Ptr; (* This is the pointer or handle to the block*)
- blkStart: LONGINT; (* the block's current starting address *)
- blkOldStart: LONGINT; (* the block's previous starting address *)
- blkSize: LONGINT; (* The length of this block (in bytes) *)
- blkSequence: INTEGER; (* A unique ID # *)
- blkPurgeable: Boolean; (* Purgeable and Locked attributes *)
- blkLocked: Boolean;
- blkDirty: Boolean; (* This tells us if the block has been changed *)
- end; (* BlockInfo *)
-
- HeapInfo = record
- blocks: array[1..MyArraySize] of BlockInfo;
- numBlocks: INTEGER; (* the total number of blocks ever allocated *)
- (* ( even if they get deallocated later ) *)
- blocksUsed: INTEGER; (* the current number of blocks allocated at this moment*)
- selectedBlock: INTEGER; (* The array index of the currently selected block *)
- maxFreeBytes: LONGINT; (* How many bytes are free *)
- maxBlocks: INTEGER; (* What's the size of the largest available block (in K) *)
- maxAvailBytes: LONGINT; (* What's the size of the largest available block (in blocks) *)
- maxAfterCompact: LONGINT; (* What's the largest block after compaction?? *)
- maxAfterPurge: LONGINT; (* What's the largest contiguous space after a purge?? *)
- heapRect: Rect; (* Our heap display's bounding rectangle *)
- end;
-
-
- var
- system: record (* Information about the machine *)
- EnhancedROMs: Boolean; (* Do we have 128K ROMs (or later)? *)
- HasWNE: Boolean; (* Is WaitNextEvent implemented? *)
- HasStyledTE: Boolean; (* Do we have Styled TextEdit (for the about box?) *)
- end;
-
- application: record (* User preferences (determined by a'pref 1000' resource *)
- UseExtendedDialog: Boolean; (* Start up with the "Advanced" dialog? (put $FFFF into *)
- (* 'pref' 1000 to enable this. *)
- end;
- MyAppZone, MyDemoZone: THz; (* My Application and "demo" heaps *)
- theMiniHeap: Ptr; (* a pointer to the start of the Demo heap *)
- OldHeap, CurrHeap: HeapInfo; (* The current and past heap info arrays *)
- BytesPerPixel: LONGINT; (* How many bytes does one line (pixel) on the display represent? *)
- MemoryDialog: DialogPtr; (* A pointer to my (one and only) display. *)
- (* Sorry guys, I'm using the Dialog Mangler. Kids: don't try this aty home! *)
- AppleMenu, FileMenu: MenuHandle; (* Can you handle this? *)
- EditMenu, WindowMenu: MenuHandle;
- SpecialMenu: MenuHandle;
- Quit: Boolean;
-
- implementation
- end.